package com.sui.bigdata.flink.sql.function.scalar;

import org.apache.flink.table.functions.ScalarFunction;

/**
 * @author YongChen
 * @date 2019/10/9 19:28
 * @description
 * @email yong_chen@sui.com
 */
public class RiskIntermediaryTag extends ScalarFunction {
    public static String IS_USER_ID = "is_user_id";

    public Integer eval(String graph_node_type, Integer zhongjie_cnt, Integer overdue_cnt, Integer loan_cnt) throws Exception {
        try {
            if (graph_node_type == null || zhongjie_cnt == null || overdue_cnt == null || loan_cnt == null || loan_cnt.intValue() == 0) {
                return 0;
            }
            if (IS_USER_ID.equals(graph_node_type) && zhongjie_cnt >= 1 && Double.valueOf(overdue_cnt) / Double.valueOf(loan_cnt) > 0.2) {
                return 1;
            }
            return 0;
        } catch (Exception e) {
            return 0;
        }
    }
}
